package com.fjut.pms.service.impl;

import java.util.HashMap;
import java.util.Map;

import com.fjut.pms.dao.IBaseDao;
import com.fjut.pms.pojo.Admin;
import com.fjut.pms.service.IAdminService;
import com.fjut.pms.utils.PageBean;

public class AdminServiceImpl implements IAdminService {

	private IBaseDao adminDao;
	
	public PageBean findAdmins(PageBean page, Object o) {
		String hql="from Admin admin where 1=1 ";
		String countHql="select count(*) from Admin admin where 1=1 ";
		return adminDao.findPageByHql(page.getPageNo(),page.getPageSize(),hql, countHql, new HashMap());
	}
	
	public boolean checkAdmin(Admin admin) {
		String hql = "from Admin admin where 1=1 and admin.no=:no and admin.password=:password";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("no", admin.getNo());
		map.put("password", admin.getPassword());
		Object o = adminDao.findByHql(hql, map);
		if (null != o)
			return true;
		return false;
	}

	public Admin findByNo(String no) {
		String hql = "from Admin admin where 1=1 and admin.no=:no";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("no", no);
		return (Admin)adminDao.findByHql(hql, map);
	}

	public IBaseDao getAdminDao() {
		return adminDao;
	}

	public void setAdminDao(IBaseDao adminDao) {
		this.adminDao = adminDao;
	}

	public void update(Admin admin) {
		adminDao.saveOrUpdate(admin);
	}
}
